<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="100" style="width: 300px;margin: auto;">


          <FormItem label="产品编号:" prop="productNo">
            <Input v-model="formLeft.productNo" :maxlength="10"/>
          </FormItem>

          <FormItem label="工艺名称:" prop="processName">
            <Input v-model="formLeft.processName" :maxlength="50" />
          </FormItem>

          <FormItem label="工艺序号:" prop="processOrder">
            <Input v-model="formLeft.processOrder" :maxlength="50"/>
          </FormItem>
          <FormItem label="工艺类型:" prop="processType">
            <Input v-model="formLeft.processType" :maxlength="50"/>
          </FormItem>
          <FormItem label="质量要求:" prop="requirement">
            <Input v-model="formLeft.requirement" :maxlength="50"/>
          </FormItem>
          <FormItem label="工艺说明:" prop="processInfo">
            <Input v-model="formLeft.processInfo" :maxlength="100" type="textarea" style="width: 200px"/>
          </FormItem>

          <row type="flex" justify="center">
            <i-col span="20">
            </i-col>
            </i-col>
            <i-col span="30">
              <Button type="primary"  @click="ProductAndProcessUpdateByProductNo">修改</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
   import {ProductAndProcessFindByProductNo,ProductAndProcessUpdateByProductNo,ProductAndProcessInsert} from "../../../api/data"

  export default {
    data() {
      return {
        formLeft: {
          productNo: '1',
          processName: '2',
          processOrder: '3',
          processType: '4',
          processInfo: '5',
          requirement: '6'
        },
        validateLibForm: {
          productNo: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          processName: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          processOrder: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          processType: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          processInfo: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          requirement: [
            {required: true, message: '请输入', trigger: 'blur'}
          ]
        }
      }
    },
    mounted() {
      const codeFlag = this.$route.query.productNo;
      if(codeFlag){
        this.formLeft.code = codeFlag;
        this.ProductAndProcessFindByProductNo();
      }
    },
    methods: {
      ProductAndProcessUpdateByProductNo() {
        if (this.formLeft.productNo !== null && this.formLeft.productNo !== "") {
          if (this.formLeft.processName !== null && this.formLeft.processName !== "") {
            if (this.formLeft.processOrder !== null && this.formLeft.processOrder !== "") {
              if(this.formLeft.processType  !== null && this.formLeft.processType !== ""){
                if(this.formLeft.processInfo !==null && this.formLeft.processInfo !== ""){
                  if(this.formLeft.requirement !==null && this.formLeft.requirement !=="") {
                    ProductAndProcessUpdateByProductNo(this.formLeft).then(res => {
                      this.$Message.success("添加成功");
                      this.$router.go(-1)
                    })
                  }
                  else {
                    this.$Message.error("质量要求不能为空");
                  }
                }
                else {
                  this.$Message.error("工艺说明不能为空");
                }
              }
              else{
                this.$Message.error("工艺类型不能为空");
              }
            }
            else {
              this.$Message.error("工艺序号不能为空");
            }
          }
          else {
            this.$Message.error("工艺名称不能为空");
          }
        }
        else {
          this.$Message.error("产品编号不能为空");
        } },
      back(){
        this.$router.go(-1);
      },
      ProductAndProcessFindByProductNo(){
        var data =  {
          code:this.formLeft.productNo,
        }
        ProductAndProcessFindByProductNo(data).then(res => {
          //console.log( res.data.data)
          this.formLeft = res.data.data;
        })
      }
    },

  }
</script>

